package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class MyCommitRollback {
	public static void main(String[] args) throws ClassNotFoundException,
			SQLException {
		Class.forName("oracle.jdbc.driver.OracleDriver");
		System.out.println("Driver loaded successfully");

		Connection con = DriverManager.getConnection(
				"jdbc:oracle:thin:@10.23.0.100:1521:esgdb10", "scott", "tiger");
		System.out.println("connection established");

		con.setAutoCommit(false);
		Statement stmt = con.createStatement();
		System.out.println("statement created..");
		int temp = 0;
		for (int i = 0; i < 5; i++) {
			temp++;
			if (temp < 3) {
				stmt.executeUpdate("INSERT INTO myTabKJ VALUES(5,'manju',21654)");
				con.rollback();
			} else {
				stmt.executeUpdate("INSERT INTO myTabKJ VALUES(5,'manju',21654)");
				con.commit();
			}
		}

	}
}
